import * as server from "@minecraft/server";
import * as power_property from "../system/power_property";
import * as realm_property from "../system/realm_property";
import * as derived_tools from "../system/derived_tools";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
export function PulsePeakCannon(object) {
    if (!realm_property.ExpendEnergy(object, -1))
        return;
    const options = {
        excludeTypes: ["minecraft:item", "minecraft:xp_orb"],
        excludeFamilies: ['player', 'starry'],
        location: object.location,
        maxDistance: 32,
        closest: 8
    };
    const targets = object.dimension.getEntities(options).filter(entity => {
        const family = entity.getComponent('type_family');
        if (entity.target?.typeId === "minecraft:player")
            return true;
        if (entity.target?.hasTag('is_Contract'))
            return true;
        if (family?.hasTypeFamily('monster'))
            return true;
    });
    if (targets.length === 0 || !realm_property.ExpendEnergy(object, -150))
        return;
    const erupt = derived_tools.IsEnable(15);
    const anchor_0 = object.offset({ x: math_tools.Random({ min: -2, max: 2 }), y: 8, z: math_tools.Random({ min: -2, max: 2 }) }) ?? object.center();
    const anchor_1 = object.offset({ x: math_tools.Random({ min: -4, max: 4 }), y: 4, z: math_tools.Random({ min: -4, max: 4 }) }) ?? object.center();
    const focus = math_tools.Vector.random(anchor_0, anchor_1);
    const powerExplode = (args) => {
        if (!object || !object.isValid())
            return;
        const options = {
            excludeTypes: ["minecraft:item", "minecraft:xp_orb"],
            excludeFamilies: ['player', 'starry'],
            location: args.location,
            maxDistance: 4,
            closest: 4
        };
        const entitys = args.dimension.getEntities(options).filter(entity => {
            const family = entity.getComponent('type_family');
            if (entity.target?.typeId === "minecraft:player")
                return true;
            if (entity.target?.hasTag('is_Contract'))
                return true;
            if (family?.hasTypeFamily('monster'))
                return true;
        });
        const bombData = power_property.CreateEmptyProperty({
            basic_attack: 15,
            erupt_odds: 45,
            erupt_hurt: 480,
            self_rune: 'rune_purple'
        });
        const player = server.world.getPlayers()[0];
        entitys.forEach(entity => achieve_plan.RunePowerAttack.BriefCreate(player, entity, erupt, bombData));
        native_tools.TrySpawnParticle(args.dimension, 'constant:fireworks_fireball_rune_purple', args.location);
    };
    achieve_plan.PathExecute.Create('脉冲尖峰炮-炮击轨迹', 1, {
        location_group: [object.center(), focus, targets[0].getHeadLocation()],
        particles: ['constant:track_rune_purple'],
        dimension: object.dimension,
        on_done: powerExplode,
        cooldown: 1,
        speed: 1
    });
}
;
